package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.CommentDto;
import com.qs.pojo.dto.GoodsInfoDto;
import com.qs.pojo.dto.StoreDto;
import com.qs.pojo.entity.Store;
import com.qs.pojo.vo.StoreVo;
import com.qs.response.Response;
import com.qs.service.IStoreCommentService;
import com.qs.service.IStoreService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商家表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-11-12
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/business")
@RequiredArgsConstructor
public class StoreController {

    private final IStoreService storeService;

    /**
     * 获取后台店铺管理分页数据
     * @param pageNo
     * @param pageSize
     * @param
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable Integer pageNo,
                         @PathVariable Integer pageSize,
                         StoreVo storeVo) {
        log.info("获取后台商户管理分页数据请求进来--------------------");
        Map<String,Object> businessMap = storeService.getList(pageNo,pageSize, storeVo);
        return Response.success(businessMap);
    }

    /**
     * 获取前台周边店铺
     * @param pageNo
     * @param pageSize
     * @param
     * @return
     */
    @GetMapping("/perimeter/list/{pageNo}/{pageSize}")
    public Response perimeterList(@PathVariable Integer pageNo,
                                  @PathVariable Integer pageSize) {
        log.info("获取前台周边店铺请求进来--------------------");
        Map<String,Object> map = storeService.getPerimeterList(pageNo,pageSize);
        return Response.success(map);
    }

    /**
     * 前台店铺搜索结果返回接口
     * @param
     * @param
     * @param
     * @return
     */
    @GetMapping("/search/store/front/{pageNo}/{pageSize}/{ids}/{msg}")
    public Response searchStoreFrontList(@PathVariable("pageNo") Integer pageNo,
                                         @PathVariable("pageSize") Integer pageSize,
                                         @PathVariable("ids") List<Integer> ids,
                                         @PathVariable("msg") String msg) throws IOException {
        log.info("前台店铺搜索结果返回接口请求进来--------------------");
        Map<String,Object>  searchStores = storeService.searchStoreFrontList(pageNo,pageSize,ids,msg);
        return Response.success(searchStores);
    }

    /**
     * 获取后台商户审核分页数据
     * @param pageNo
     * @param pageSize
     * @param
     * @return
     */
    @GetMapping("/check/list/{pageNo}/{pageSize}")
    public Response getStoreCheckList(@PathVariable Integer pageNo,
                         @PathVariable Integer pageSize,
                         StoreVo storeVo) {
        log.info("获取后台商户审核分页数据请求进来--------------------");
        Map<String,Object> businessMap = storeService.getStoreCheckList(pageNo,pageSize, storeVo);
        return Response.success(businessMap);
    }

    /**
     * 获取审核未通过和审核中的店铺数
     * @return
     */
    @GetMapping("/count")
    public Response getStoreCounts() {
        log.info("获取审核未通过和审核中的店铺数请求进来--------------------");
        Long counts = storeService.getStoreCounts();
        return Response.success(counts);
    }

    /**
     * 商户获取审核已通过的未读通知数
     * @return
     */
    @GetMapping("/store/read/count/{userId}")
    public Response getStoreIsReadCounts(@PathVariable("userId") Integer userId) {
        log.info("商户获取审核已通过的未读通知数请求进来--------------------");
        Map<String,Object> countMap = storeService.getStoreIsReadCounts(userId);
        return Response.success(countMap);
    }

    /**
     * 商户已读全部通知接口
     * @return
     */
    @PostMapping("/all/read/{userId}")
    public Response allRead(@PathVariable("userId") Integer userId) {
        log.info("商户已读全部通知接口请求进来--------------------");
        storeService.allRead(userId);
        return Response.success();
    }

    /**
     * 获取前台商户信息及商品分页数据
     * @param pageNo
     * @param pageSize
     * @param
     * @return
     */
    @GetMapping("/front/info/list/{pageNo}/{pageSize}/{storeId}")
    public Response getStoresInfo(@PathVariable Integer pageNo,
                                  @PathVariable Integer pageSize,
                                  @PathVariable Integer storeId) {
        log.info("获取前台商户信息及商品分页数据请求进来--------------------");
        Map<String,Object> storesInfo = storeService.getStoresInfo(pageNo,pageSize,storeId);
        return Response.success(storesInfo);
    }

    /**
     * 获取前台店铺推荐商品
     * @param storeId
     * @return
     */
    @GetMapping("/shop/recommend/list/{storeId}")
    public Response searchRecommendGoods(@PathVariable Integer storeId) {
        log.info("获取前台店铺推荐商品数据请求进来--------------------");
        //todo: 后台应该设置添加商品时是否要推荐商品，然后从推荐的商品中获取
        List<GoodsInfoDto> list = storeService.searchRecommendGoods(storeId);
        return Response.success(list);
    }

    /**
     * 前台获取商户数据
     * @param userId
     * @param
     * @return
     */
    @GetMapping("/front/list/{userId}")
    public Response frontList(@PathVariable Integer userId) {
        log.info("前台获取商户数据请求进来--------------------");
        List<StoreDto> businessList = storeService.getFrontList(userId);
        return Response.success(businessList);
    }

    /**
     * 新增店铺
     * @param store
     * @return
     */
    @PostMapping("/save")
    @OperationLog(operModul = "店铺管理-新增店铺",operDesc = "商户新增店铺")
    public Response saveStore(@RequestBody Store store) {
        log.info("新增商户请求进来--------------------");
        storeService.saveStore(store);
        return Response.success();
    }

    /**
     * 管理员审核通过店铺接口
     * @param
     * @param
     * @param
     * @return
     */
    @PutMapping("/check/update")
    @OperationLog(operModul = "店铺管理-审核店铺",operDesc = "管理员审核通过店铺接口")
    public Response checkStorePass(@RequestBody StoreDto storeDto) {
        log.info("管理员审核通过店铺接口请求进来--------------------");
        storeService.checkStorePass(storeDto);
        return Response.success();
    }

    /**
     * 修改商户
     * @param
     * @param
     * @param
     * @return
     */
    @PutMapping("/update")
    @OperationLog(operModul = "店铺管理-修改商户",operDesc = "修改商户")
    public Response update(@RequestBody StoreDto storeDto) {
        log.info("修改商户请求进来--------------------");
        storeService.updateByKey(storeDto);
        return Response.success();
    }

    /**
     * 商户数据回显
     * @param
     * @param
     * @param
     * @return
     */
    @GetMapping("/getById/{id}")
    public Response echo(@PathVariable Integer id) {
        log.info("商户数据回显请求进来--------------------");
        StoreDto storeDto = storeService.echo(id);
        return Response.success(storeDto);
    }

    /**
     * 删除商户
     * @param
     * @param
     * @param
     * @return
     */
    @DeleteMapping("/remove/{ids}/{userId}")
    @OperationLog(operModul = "店铺管理-删除商户",operDesc = "删除商户")
    public Response delete(@PathVariable List<Integer> ids,
                           @PathVariable("userId") Integer userId) {
        log.info("删除商户请求进来--------------------");
        storeService.delete(ids,userId);
        return Response.success();
    }
}
